#include <stdio.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <poll.h>
#include <sys/mman.h>
#include <string.h>
#include <unistd.h>

#define RED 	0x00FF0000
#define ORANGE 	0x00FFA500
#define YELLOW 	0x00FFFF00
#define GREEN 	0x0000FF00
#define DGREEN 	0x00008000
#define BLUE 	0x000000FF
#define PURPLE 	0x00800080
#define MVRED 	0x00C71585
#define WHITE 	0xFFFFFFFF

int main(int argc, char const *argv[])
{
	//打开设备
	int lcd = open("/dev/ubuntu_lcd", O_RDWR);
	char *p = mmap(NULL, 800*480*4, PROT_WRITE, MAP_SHARED, lcd, 0);
	//内存清零
	bzero(p,480*800*4);
	//创建颜色(防越界，多写了一组)
	int color[] = {RED,ORANGE,YELLOW,GREEN,DGREEN,BLUE,PURPLE,WHITE,RED,ORANGE,YELLOW,GREEN,DGREEN,BLUE,PURPLE,WHITE};

	int i,j,k;
	//开始填充颜色
	for(k=0;k<=8;k++)
	{
		for(i=0;i<240;i++)  //色块列
		{
			int lcd_lines = 800*4*i;
			for(j=0;j<200;j++)  //色块行
			{
				//第一行
				memcpy(p+lcd_lines+4*j+(200*0*4),&color[k+0],4);
				memcpy(p+lcd_lines+4*j+(200*1*4),&color[k+1],4);
				memcpy(p+lcd_lines+4*j+(200*2*4),&color[k+2],4);
				memcpy(p+lcd_lines+4*j+(200*3*4),&color[k+3],4);
				//第二行
				memcpy(p+lcd_lines+4*j+(200*0*4)+(800*240*4),&color[k+7],4);
				memcpy(p+lcd_lines+4*j+(200*1*4)+(800*240*4),&color[k+6],4);
				memcpy(p+lcd_lines+4*j+(200*2*4)+(800*240*4),&color[k+5],4);
				memcpy(p+lcd_lines+4*j+(200*3*4)+(800*240*4),&color[k+4],4);
			}
			
		}
		sleep(1);
		if(k==8) k=0;
	}
	munmap(p,800*480*4);
	close(lcd);	
	return 0;
	 
}

